#include "Pch.h"
#include "ScriptConfig.h"
#include "ICScriptInterface.h"
/*#include <CoreDir.h>*/
/*#include <boost/filesystem.hpp>*/
using namespace rapidxml;

static CScriptConfig * gCScriptConfig = NULL;
CScriptConfig::CScriptConfig(void)
{
	gCScriptConfig = this;
}

CScriptConfig::~CScriptConfig(void)
{

}

std::string CScriptConfig::getScriptsPath(const std::string & filename)
{
	//char path[ MAX_PATH ];
	//::GetModuleFileNameA( NULL, path, MAX_PATH );
	//boost::filesystem::path media_file = CScriptInterface::getMe()->getCoreDir()->getMediaDir( "Engine","Scripts" );
	//media_file /= filename;
	//return media_file.string();
	std::string path = CScriptInterface::getMe()->getMediaDir();
	//path += "//";
	path += filename;
	return path;
}

void CScriptConfig::loadConfig()
{
	std::string df = getScriptsPath("ScriptsConsfig.xml").c_str() ;

	file<> fdoc( getScriptsPath("ScriptsConsfig.xml").c_str() );
	xml_document<> doc;    
	doc.parse< 0 >( fdoc.data() ); 
	xml_node<> * node_root = doc.first_node( "Media" );

	xml_node<> * node_Vals = node_root->first_node( "Vals" );
	if (node_Vals)
	{
		xml_node<> * node_Val = node_Vals->first_node( "Val" );
		while ( node_Val )
		{
			std::string media_name = node_Val->first_attribute( "Name" )->value();
			std::string	TypeValue = node_Val->first_attribute( "Type" )->value();
			std::string	Value = node_Val->first_attribute( "Value" )->value();
			if (TypeValue == "int")
			{
				ICVar * val = CXConsole::GetGlobalInstance()->RegisterInt(media_name.c_str(),atoi(Value.c_str()) ,VF_NULL);
				val->Set(atoi(Value.c_str()));
				// 				int tet = val->GetIVal();
				// 				tet++;
			}
			node_Val = node_Val->next_sibling();
		}
	}
}




